#include "standgas_cali.h"

StandGas_cali::StandGas_cali(QWidget *parent) : QMainWindow(parent)
{

    Sysctrl->SYS_CTL_MODE =0;
    this->setStyleSheet("QMainWindow{background-image: url(:/pic/背景板.png);}");
    this->setFixedSize(640,430);
    timer = new QTimer(this);
    timer->start(1000);

    UI_Init();
    connect_Init();
    update_data();

}

void StandGas_cali::UI_Init()
{

    the_btn_style[0]=("\
                      outline: 0px ;                            /* 去掉获取焦点时的虚线 */ \
                      background-color: rgb(0, 170, 255);	    /* 背景颜色 */\
                      border-radius: 6px;		                 /* 按钮边框的圆角设置 */\
                      border-style: outset;\
                      /* 按钮背景图标设置 */\
                      background-image: url(:/pic/access/气象站.png); /* 背景图片 */\
                      background-origin: content;\
                      background-position: left;	         /* 背景图片的位置 */\
                      padding-right: 0px;	    /*内边距设置*/	    \
                      padding-left: 10px;		/*  */	\
                      padding-bottom: 10px;		/*  */    \
                      padding-top: 10px;		/*  */    \
                      background-repeat: no-repeat;	         /* 设置背景图像的平铺模式 */\
                      /* 按钮文本设置 */\
                      text-align: content;			             /* 文本的位置 */\
                      font-size: 18px;\
                      color: #FFFFFF;			                 /* 文本颜色 */\
                 "
);

//
the_btn_style[2]=("QPushButton:pressed{background-color:rgb(99,211,133);}");
the_btn_style[1]=("\
                  outline: 0px ;                            /* 去掉获取焦点时的虚线 */ \
                  border-radius: 8px;		                 /* 按钮边框的圆角设置 */\
                  border-style: outset;\
                  /* 按钮背景图标设置 */\
                  background-image: url(:/pic/Airflow_mode/等待.png); /* 背景图片 */\
                  background-origin: content;\
                  background-position: left;	         /* 背景图片的位置 */\
                  padding-right: 0px;	    /*内边距设置*/	    \
                  padding-left: 10px;		/*  */	\
                  padding-bottom: 10px;	/*  */   \
                  padding-top:10px;		/*  */    \
                  background-repeat: repeat;	         /* 设置背景图像的平铺模式 */\
                  /* 按钮文本设置 */\
                  text-align:content ;			             /* 文本的位置 */\
                  font-size: 22px;\
                  color: rgb(225, 225, 225);			                 /* 文本颜色 */\
                  ");

                  for(int i=0;i<8;i++)//创建主屏幕显示的按键
                  {
                       theBtn[i] = new QPushButton(this);
              //        newbutton->setGeometry(30+(i*150),260,120,90 );//设定每隔放置一个按键
                       theBtn[i]->setFixedSize(145,36);
                      theBtn[i]->geometry();
                      btnlist_ui.append(theBtn[i]);
                  }
                  theBtn[0]->setStyleSheet(  "QPushButton{"+the_btn_style[0]+"background-color: rgb(255, 150, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/GESYTEC系列号.png); /* 背景图片 */"+"}"
                   "QPushButton:focus{"+the_btn_style[1]+"background-color: rgb(255, 50, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/GESYTEC系列号.png); /* 背景图片 */"+"}");
                  theBtn[1]->setStyleSheet(  "QPushButton{"+the_btn_style[0]+"background-color: rgb(255, 150, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/TCP IP设置.png); /* 背景图片 */"+"}"
                   "QPushButton:focus{"+the_btn_style[1]+"background-color: rgb(255, 50, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/TCP IP设置.png); /* 背景图片 */"+"}");
                  theBtn[2]->setStyleSheet(  "QPushButton{"+the_btn_style[0]+"background-color: rgb(255, 150, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/仪器识别号.png); /* 背景图片 */"+"}"
                   "QPushButton:focus{"+the_btn_style[1]+"background-color: rgb(255, 50, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/仪器识别号.png); /* 背景图片 */"+"}");
                  theBtn[3]->setStyleSheet(  "QPushButton{"+the_btn_style[0]+"background-color: rgb(255, 150, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/数据流配置.png); /* 背景图片 */"+"}"
                   "QPushButton:focus{"+the_btn_style[1]+"background-color: rgb(255, 50, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/数据流配置.png); /* 背景图片 */"+"}");
                  theBtn[4]->setStyleSheet(  "QPushButton{"+the_btn_style[0]+"background-color: rgb(255, 150, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/通讯协议.png); /* 背景图片 */"+"}"
                   "QPushButton:focus{"+the_btn_style[1]+"background-color: rgb(255, 50, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/通讯协议.png); /* 背景图片 */"+"}");
                  theBtn[5]->setStyleSheet(  "QPushButton{"+the_btn_style[0]+"background-color: rgb(255, 150, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/串口设置.png); /* 背景图片 */"+"}"
                   "QPushButton:focus{"+the_btn_style[1]+"background-color: rgb(255, 50, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/串口设置.png); /* 背景图片 */"+"}");
                  theBtn[6]->setStyleSheet(  "QPushButton{"+the_btn_style[0]+"background-color: rgb(255, 150, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/GESYTEC系列号.png); /* 背景图片 */"+"}"
                   "QPushButton:focus{"+the_btn_style[1]+"background-color: rgb(255, 50, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/background/GESYTEC系列号.png); /* 背景图片 */"+"}");
                  theBtn[7]->setStyleSheet(  "QPushButton{"+the_btn_style[0]+"background-color: rgb(255, 150, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/返回.png); /* 背景图片 */"+"}"
                   "QPushButton:focus{"+the_btn_style[1]+"background-color: rgb(255, 50, 55);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/返回2.png); /* 背景图片 */"+"}");

                 btnlist_ui.at(0)->setText(tr("    5 %"));
                 btnlist_ui.at(1)->setText(tr("    20 %"));
                 btnlist_ui.at(2)->setText(tr("    35 %"));
                 btnlist_ui.at(3)->setText(tr("    50 %"));
                 btnlist_ui.at(4)->setText(tr("    60 %"));
                 btnlist_ui.at(5)->setText(tr("    80  %"));
                 btnlist_ui.at(6)->setText(tr("    90  %"));
                 btnlist_ui.at(7)->setText(tr("     返回"));


                  for(int i=0;i<10;i++)//创建主屏幕显示的按键
                  {
                       theLabel[i] = new QLabel(this);
                       theLabel[i]->setStyleSheet("QLabel{\
                                              outline: 0px ;                            /* 去掉获取焦点时的虚线 */ \
                                              border-radius: 6px;		                 /* 按钮边框的圆角设置 */\
                                              border-style: outset;\
                                              /* 按钮文本设置 */\
                                              qproperty-alignment: 'AlignCenter| AlignCenter';			             /* 文本的位置 */\
                                              font-size: 20px;\
                                              color: #123567;			                 /* 文本颜色 */\
                                         }"
                        );
                  }
                  theLabel[0]->setStyleSheet("QLabel{ image: url(:/pic/logo.png); background-color: rgb(20, 170, 225);}"    );
                  theLabel[0]->setStyleSheet("QLabel{"
                                        + the_StyleSheet[20]+ " font-size: 25px;"+ "background-color: rgb(20, 70, 255);	    /* 背景颜色 */"+  "}"    );
                  theLabel[1]->setStyleSheet("QLabel{ image: url(:/pic/左.png); }"    );
                  theLabel[2]->setStyleSheet("QLabel{ image: url(:/pic/右.png); }"    );

                 theLabel[0]->setGeometry(0,0,640,60);//设定每隔放置一个按键
                 theLabel[1]->setGeometry(0,0,300,60);//设定每隔放置一个按键
                 theLabel[2]->setGeometry(340,0,300,60);//设定每隔放置一个按键
                 theLabel[0]->setText("串口设置");

                 //事件过滤器
                 foreach (QPushButton *btn, btnlist_ui) {
                     btn->installEventFilter(this);
                 }

                 QGridLayout *theLayout = new QGridLayout();
//                 theLayout->setAlignment(Qt::AlignCenter);
                 theLayout->addWidget(btnlist_ui.at(0), 1, 0);
                 theLayout->addWidget(btnlist_ui.at(1), 2, 0);
                 theLayout->addWidget(btnlist_ui.at(2), 3, 0);
                 theLayout->addWidget(btnlist_ui.at(3), 4, 0);
                 theLayout->addWidget(btnlist_ui.at(4), 5, 0);
                 theLayout->addWidget(btnlist_ui.at(5), 6, 0);
                 theLayout->addWidget(btnlist_ui.at(6), 7, 0);
                 theLayout->addWidget(btnlist_ui.at(7), 8, 0);
                 theLayout->addWidget(theLabel[3], 1, 2);
                 theLayout->addWidget(theLabel[4], 2, 2);
                 theLayout->addWidget(theLabel[5], 3, 2);
                 theLayout->addWidget(theLabel[6], 4, 2);
                 theLayout->addWidget(theLabel[7], 5, 2);
                 theLayout->addWidget(theLabel[8], 6, 2);
                 theLayout->addWidget(theLabel[9], 7, 2);

                 theLayout->setContentsMargins(50,90,50,50);//(int left, int top, int right, int bottom)
                 theLayout->setSizeConstraint(QLayout::SetMinimumSize);
                   setLayout(theLayout);

                   QWidget* widget = new QWidget(this);
                   widget->setGeometry(0,0,640,330);
                   widget->setLayout(theLayout);
                   }
void StandGas_cali::update_data()
                   {

                       //显示状态
//    if(Sysset->MFC_Zero_Cal.cal_5_FS >1)
        theLabel[3]->setText("FS         "+QString::number(Sysset->MFC_Zero_Cal.cal_5_FS/1000,'f',0)+"         SCCM");

//    if(Sysset->MFC_Zero_Cal.cal_20_FS >1)
        theLabel[4]->setText("FS         "+QString::number(Sysset->MFC_Zero_Cal.cal_20_FS/1000,'f',0)+"         SCCM");

//    if(Sysset->MFC_Zero_Cal.cal_35_FS >1)
        theLabel[5]->setText("FS         "+QString::number(Sysset->MFC_Zero_Cal.cal_35_FS/1000,'f',0)+"         SCCM");

//    if(Sysset->MFC_Zero_Cal.cal_50_FS >1)
        theLabel[6]->setText("FS         "+QString::number(Sysset->MFC_Zero_Cal.cal_50_FS/1000,'f',0)+"         SCCM");

//    if(Sysset->MFC_Zero_Cal.cal_65_FS >1)
        theLabel[7]->setText("FS         "+QString::number(Sysset->MFC_Zero_Cal.cal_65_FS/1000,'f',0)+"         SCCM");

//    if(Sysset->MFC_Zero_Cal.cal_80_FS >1)
        theLabel[8]->setText("FS         "+QString::number(Sysset->MFC_Zero_Cal.cal_80_FS/1000,'f',0)+"         SCCM");

//    if(Sysset->MFC_Zero_Cal.cal_95_FS>1)
        theLabel[9]->setText("FS         "+QString::number(Sysset->MFC_Zero_Cal.cal_95_FS/1000,'f',0)+"         SCCM");

                   }


void StandGas_cali::connect_Init()
{

    //定时器
    connect(timer,&QTimer::timeout,[=](){
update_data();
    });

    connect(btnlist_ui.at(0),&QPushButton::clicked,[=](){
        flag_datastand=5;
        Stand_flowDataset *dataset = new Stand_flowDataset(this);
        this->hide();
        dataset->show();
    });
    connect(btnlist_ui.at(1),&QPushButton::clicked,[=](){
        flag_datastand=20;
        Stand_flowDataset *dataset = new Stand_flowDataset(this);
        this->hide();
        dataset->show();
    });
    connect(btnlist_ui.at(2),&QPushButton::clicked,[=](){
        flag_datastand=35;
        Stand_flowDataset *dataset = new Stand_flowDataset(this);
        this->hide();
        dataset->show();
    });
    connect(btnlist_ui.at(3),&QPushButton::clicked,[=](){
        flag_datastand=50;
        Stand_flowDataset *dataset = new Stand_flowDataset(this);
        this->hide();
        dataset->show();
    });
    connect(btnlist_ui.at(4),&QPushButton::clicked,[=](){
        flag_datastand=65;
        Stand_flowDataset *dataset = new Stand_flowDataset(this);
        this->hide();
        dataset->show();
    });
    connect(btnlist_ui.at(5),&QPushButton::clicked,[=](){
        flag_datastand=80;
        Stand_flowDataset *dataset = new Stand_flowDataset(this);
        this->hide();
        dataset->show();
    });
    connect(btnlist_ui.at(6),&QPushButton::clicked,[=](){
        flag_datastand=95;
        Stand_flowDataset *dataset = new Stand_flowDataset(this);
        this->hide();
        dataset->show();
    });

    //返回按钮
    connect(btnlist_ui.at(7),&QPushButton::clicked,[=](){
        this->parentWidget()->show();
        this->close();
        Sysctrl->Para_Save = 1;
    });




}

bool StandGas_cali::eventFilter(QObject *watched, QEvent *event)
    {

            for(int i=0;i<btnlist_ui.length();i++)
                if(btnlist_ui.at(i) == watched)
            {
                if(event->type() == QEvent::KeyPress)
                {
                   QKeyEvent *ev = (QKeyEvent *)event;
                   QPushButton *button = (QPushButton *)watched;
                   switch (ev->key())
                   {
                   case OK:
                     {
                       emit  button->clicked();
                       break;
                     }
                   case UP://上
                   {
                       if(focusWidget() != btnlist_ui.first())
                       focusPreviousChild();
                       break;
                   }
                   case DOWN://下
                   {
                       if(focusWidget() != btnlist_ui.back())
                       focusNextChild();
                       break;
                   }
                   case LEFT://左
                   {
                     if(focusWidget() != btnlist_ui.first())
                          focusPreviousChild();
                     break;
                   }
                   case RIGHT://右
                   {
                     if(focusWidget() != btnlist_ui.back())
                          focusNextChild();
                  break;
                   }
                   case INIT: //打开初始化界面
                   {
                       init_Show *show = new init_Show(this);
                       show->show();
                       this->hide();
                       break;
                   }
                   case BACK:
                   {
                       this->parentWidget()->show();
                       this->close();
                       break;
                   }
                   default:
                       break;
                   }
                }

                }
           return QMainWindow::eventFilter(watched,event);//返回父类的事件过滤器

    }
